
<template>
  <div>
    <div class="app-container" id="appss">
      <div id="ps" style="width:100%;height:400px;"></div>
      <table width="100%" class="table-top" border="0">
        <tr>
          <th width="41%" colspan="6">政策备注信息</th>
          <th colspan="6" width="59%">
            <table width="100%" border="0" class="table-two">
              <tr>
                <th rowspan="2" width="16%">上/下游</th>
                <th colspan="2" width="34%" style="border-width: 0px 1px 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: white; border-bottom-color: white; border-left-color: white; border-image: initial;">交强险</th>
                <th colspan="2" width="34%" style="border-width: 0px 1px 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: white; border-bottom-color: white; border-left-color: white; border-image: initial;">商业险</th>
                <th rowspan="2" width="16%">操作</th>
              </tr>
              <tr>
                <th width="17%">佣金</th>
                <th width="17%" style="border-right: 1px solid white;">奖励</th>
                <th width="17%">佣金</th>
                <th width="17%">奖励</th>
              </tr>
            </table>
          </th>
        </tr>
      </table>
      <table width="100%" class="table-one" border="0">
        <tr>
          <td rowspan="3" width="10%">
            家庭自用6座
          </td>
          <td width="10%">
            含车损业务
          </td>
          <td colspan="4" width="21%">
            保费类型1
          </td>
          <td colspan="6" width="59%">
            <div>
              row1
            </div>
          </td>
        </tr>
        <tr>
          <td rowspan="2">不含车损业务</td>
          <td colspan="4">
            保费类型2
          </td>
          <td colspan="6">
            <div>row2</div>
          </td>
        </tr>
        <tr>
          <td colspan="4">
            车辆种类2
          </td>
          <td colspan="6">
            <div style="width:100%;" v-for='(item,indexout) in policylist' :key="item.id">
              <template v-if="indexout == 0"> <!--0就是行号-->
                <div class="tables_contentall">
                  <div class="tables_line">
                    <div class="tables_contentall_in">
                      <div class="tables_content2">
                        {{item.name}}
                        <el-popover placement="top" width="280" :ref="'popadd'+indexout">
                          <el-form :model="batchChild" :rules="rules" ref="batchChild" label-width="150px">

                            <el-form-item label="子机构" label-width="70px" prop="targetId">
                              <el-select v-if="!isSingle" no-data-text="无部门可选" class="wd150" v-model="batchChild.targetId" size="mini" placeholder="请选择子机构">
                                <el-option v-for="item in organization" :label="item.organizationName" :key="item.organizationId" :value="item.organizationId"></el-option>
                              </el-select>
                              <el-select v-if="isSingle" no-data-text="无部门可选" class="wd150" v-model="batchChild.targetId" size="mini" placeholder="请选择子机构">
                                <el-option v-for="item in childorganization" :label="item.organizationName" :key="item.organizationId" :value="item.organizationId"></el-option>
                              </el-select>
                            </el-form-item>

                          </el-form>
                          <div style="text-align: right; margin: 0">
                            <el-button size="mini" type="text" @click="cancelpop('popadd'+indexout)">取消</el-button>
                            <el-button type="primary" size="mini" @click.stop="saveBatchchild('batchChild')" :loading="childloding">确定</el-button>
                          </div>
                          <i  slot="reference" title="添加子机构" class="iconfont icon-plus" @click="singleAdd(item.policyId,indexout)"></i>
                        </el-popover>
                        
                        <!-- singleAdd(policyid)  传该行政策的id -->
                      </div>
                      <div class="tables_content3" slot="reference" :class="item.isbackshow?'backshows':''">
                        <span class="tables_top3_frame tables_content3_inp">
                          <span class="tables_content3_inpin" :class="item.change1?'ischange1':''">
                            <span v-if="item.lowerChargeType==1">-</span>
                            <!-- focusselect($event) 传输入框的event对象，实现文字被选中状态 -->
                            <!--getchange_num($event,indexout,"lowerBrokerageTraffic",item.lowerBrokerageBusinessType)  
                              传（输入框的event对象，该行的行号 从0开始，"lowerBrokerageTraffic"，该行的lowerBrokerageBusinessType类型）
                          -->
                            <input type="text" @focus="focusselect($event)" :class="{'isfrontshow':item.isfront,'isdis':iscanedit}" :disabled="iscanedit" class="inputset" v-model="item.brokerageTraffic" @input='getchange_num($event,indexout,"brokerageTraffic",item.brokerageTraffic)' />
                            <span v-if="item.lowerBrokerageBusinessType==0" class="Percentage_color">%</span>
                            <span v-else class="Percentage_color">元</span>
                          </span>
                          <span class="tables_content3_inpin" :class="item.change2?'ischange2':''">
                            <span v-if="item.lowerChargeType==1">-</span>
                            <!-- focusselect($event) 传输入框的event对象，实现文字被选中状态 -->
                            <!--getchange_num($event,indexout,"lowerRewardTraffic",item.lowerBrokerageBusinessType)  
                              传（输入框的event对象，该行的行号，"lowerRewardTraffic"，该行的lowerBrokerageBusinessType类型）
                          -->
                            <input type="text" @focus="focusselect($event)" :class="{'isfrontshow':item.isfront,'isdis':iscanedit}" :disabled="iscanedit" class="inputset" @input='getchange_num($event,indexout,"rewardTraffic",item.rewardTraffic)' v-model="item.rewardTraffic" />
                            <span v-if="item.lowerBrokerageBusinessType ==0" class="Percentage_color">%</span>
                            <span v-else class="Percentage_color">元</span>
                          </span>
                        </span>
                        <span class="tables_content3_inp" :class="item.change3?'ischange3':''">
                          <span class="tables_content3_inpin">
                            <span v-if="item.lowerChargeType==1">-</span>
                            <!-- focusselect($event) 传输入框的event对象，实现文字被选中状态 -->
                            <!--getchange_num($event,indexout,"lowerBrokerageBusiness",item.lowerBrokerageBusinessType)  
                              传（输入框的event对象，该行的行号，"lowerBrokerageBusiness"，该行的lowerBrokerageBusinessType类型）
                          -->
                            <input type="text" @focus="focusselect($event)" :class="{'isseconshow':item.issecon,'isdis':iscanedit}" :disabled="iscanedit" class="inputset" v-model="item.lowerBrokerageBusiness" @input='getchange_num($event,indexout,"lowerBrokerageBusiness",item.lowerBrokerageBusinessType)' />
                            <span v-if="item.lowerBrokerageBusinessType ==0" class="Percentage_color">%</span>
                            <span v-else class="Percentage_color">元</span>
                          </span>
                          <span class="tables_content3_inpin" :class="item.change4?'ischange4':''">
                            <span v-if="item.lowerChargeType==1">-</span>
                            <!-- focusselect($event) 传输入框的event对象，实现文字被选中状态 -->
                            <!--getchange_num($event,indexout,"lowerRewardBusiness",item.lowerBrokerageBusinessType)  
                              传（输入框的event对象，该行的行号，"lowerRewardBusiness"，该行的lowerBrokerageBusinessType类型）
                          -->
                            <input type="text" @focus="focusselect($event)" :class="{'isseconshow':item.issecon,'isdis':iscanedit}" :disabled="iscanedit" class="inputset" v-model="item.lowerRewardBusiness" @input='getchange_num($event,indexout,"lowerRewardBusiness",item.lowerBrokerageBusinessType)' />
                            <span v-if="item.lowerBrokerageBusinessType ==0" class="Percentage_color">%</span>
                            <span v-else class="Percentage_color">元</span>
                          </span>
                        </span>
                        <div class="poper_operation">
                          <!-- subfalse(indexout)  传（该行的行号） -->
                          <!--  subpolicy(item,indexout)  传（该行的对象信息，该行的行号）-->
                          <span type="text" @click="subfalse(indexout)">取消</span>
                          <span type="text" @click="subpolicy(item,indexout)">保存</span>
                        </div>
                      </div>
                      <div style="clear:both"></div>
                    </div>
                    <div class="tables_content4">
                      <template>
                        <!--toDetail(item.policyId,'01')   传（该行政策的id，'01'）  -->
                        <a @click="toDetail(item.policyId,'01')">详情</a>
                      </template>
                    </div>
                    <div style="clear:both"></div>
                  </div>
                  <template v-if="item.childOrgs !== null">
                    <div class="tables_line" v-for="(val,index) in item.childOrgs">
                      <div class="tables_contentall_in">
                        <div class="tables_content2">
                          <span :title="val.describe[0]">{{val.describe[0]}}</span>
                          <!--deletChild(item.policyId,val.policyItemRateId)  传（该行政策的id，该子机构的id）  -->
                          <i class="iconfont icon-shanchu" title="删除子机构" @click="deletChild(item.policyId,val.policyItemRateId)"></i>
                        </div>
                        <div class="tables_content3" slot="reference" :class="val.isbackshow?'backshows':''">
                          <span class="tables_top3_frame tables_content3_inp">
                            <span class="tables_content3_inpin" :class="val.change1?'ischange1':''">
                              <span v-if="val.chargeType==1">-</span>
                              <!-- focusselect($event) 传输入框的event对象，实现文字被选中状态 -->
                              <!--getchange_extendnum($event,indexout,index,"lowerBrokerageTraffic",val.brokerageBusinessType)  
                              传（输入框的event对象，该行的行号，"lowerBrokerageTraffic"，该行的子机构的brokerageBusinessType类型）
                          -->
                              <input type="text" @focus="focusselect($event)" :class="{'isfrontshow':val.isfront,'isdis':iscanedit}" :disabled="iscanedit" v-model="val.lowerBrokerageTraffic" class="inputset" @input='getchange_extendnum($event,indexout,index,"lowerBrokerageTraffic",val.brokerageBusinessType)' />
                              <span v-if="val.brokerageBusinessType==0" class="Percentage_color">%</span>
                              <span v-else class="Percentage_color">元</span>
                            </span>
                            <span class="tables_content3_inpin" :class="val.change2?'ischange2':''">
                              <span v-if="val.chargeType==1">-</span>
                              <!-- focusselect($event) 传输入框的event对象，实现文字被选中状态 -->
                              <!--getchange_extendnum($event,indexout,index,"lowerRewardTraffic",val.brokerageBusinessType)  
                              传（输入框的event对象，该行的行号，"lowerRewardTraffic"，该行的子机构的brokerageBusinessType类型）
                          -->
                              <input type="text" @focus="focusselect($event)" :class="{'isfrontshow':val.isfront,'isdis':iscanedit}" :disabled="iscanedit" v-model="val.lowerRewardTraffic" class="inputset" @input='getchange_extendnum($event,indexout,index,"lowerRewardTraffic",val.brokerageBusinessType)' />
                              <span v-if="val.brokerageBusinessType==0" class="Percentage_color">%</span>
                              <span v-else class="Percentage_color">元</span>
                            </span>
                          </span>
                          <span class="tables_content3_inp">
                            <span class="tables_content3_inpin" :class="val.change3?'ischange3':''">
                              <span v-if="val.chargeType==1">-</span>
                              <!-- focusselect($event) 传输入框的event对象，实现文字被选中状态 -->
                              <!--getchange_extendnum($event,indexout,index,"lowerBrokerageBusiness",val.brokerageBusinessType)  
                              传（输入框的event对象，该行的行号，"lowerBrokerageBusiness"，该行的子机构的brokerageBusinessType类型）
                          -->
                              <input @focus="focusselect($event)" type="text" :class="{'isseconshow':val.issecon,'isdis':iscanedit}" :disabled="iscanedit" v-model="val.lowerBrokerageBusiness" class="inputset" @input='getchange_extendnum($event,indexout,index,"lowerBrokerageBusiness",val.brokerageBusinessType)' />
                              <span v-if="val.brokerageBusinessType==0" class="Percentage_color">%</span>
                              <span v-else class="Percentage_color">元</span>
                            </span>
                            <span class="tables_content3_inpin" :class="val.change4?'ischange4':''">
                              <span v-if="val.chargeType==1">-</span>
                              <!-- focusselect($event) 传输入框的event对象，实现文字被选中状态 -->
                              <!--getchange_extendnum($event,indexout,index,"lowerRewardBusiness",val.brokerageBusinessType)  
                              传（输入框的event对象，该行的行号，"lowerRewardBusiness"，该行的子机构的brokerageBusinessType类型）
                          -->
                              <input @focus="focusselect($event)" type="text" :class="{'isseconshow':val.issecon,'isdis':iscanedit}" :disabled="iscanedit" v-model="val.lowerRewardBusiness" class="inputset" @input='getchange_extendnum($event,indexout,index,"lowerRewardBusiness",val.brokerageBusinessType)' />
                              <span v-if="val.brokerageBusinessType==0" class="Percentage_color">%</span>
                              <span v-else class="Percentage_color">元</span>
                            </span>
                          </span>
                          <div class="poper_operation">
                            <!-- subfalseextend(indexout，index)  传（该条政策的行号，政策里子机构的行号） -->
                            <!--  subpolicychildOrgs(val,indexout,index)  传（该子机构的对象信息，该条政策的行号，政策里子机构的行号）-->
                            <span type="text" @click="subfalseextend(indexout,index)">取消</span>
                            <span type="text" @click="subpolicychildOrgs(val,indexout,index)">保存</span>
                          </div>
                        </div>
                        <div style="clear:both"></div>
                      </div>
                      <div class="tables_content4">
                        <template>
                          <!--toDetail(item.policyId,'01')   传（该行政策的id，'01'）  -->
                          <a @click="toDetail(item.policyId,'01')">详情</a>
                          <el-popover placement="bottom-end" width="250" :ref='"aa"+indexout' v-model="item.delete_show">
                            <p class="candeletes">确定删除吗？</p>
                            <div style="text-align: right; margin: 0">
                              <!-- deletefalse('aa'+indexout)  传('aa'+该条政策的行号) -->
                              <!-- deletepolicy(item.policyId,indexout,'aa'+indexout) 传（该条政策的id，该条政策的行号,'aa'+该条政策的行号） -->
                              <el-button size="mini" type="text" @click="deletefalse('aa'+indexout)">取消</el-button>
                              <el-button type="primary" size="mini" @click="deletepolicy(item.policyId,indexout,'aa'+indexout)">确定</el-button>
                            </div>
                            <a class="tablescont_right_delete" slot="reference" ref="tanindexs">删除</a>
                          </el-popover>
                        </template>
                      </div>
                      <div style="clear:both"></div>
                    </div>
                  </template>

                </div>
              </template>

            </div>
          </td>
        </tr>
        <tr>
          <td width="41%" colspan="6"></td>
          <td width="59%" colspan="6">
            <div style="width:100%;min-height:45px;line-height:45px;">
              <div class="tables_bom_son">
                <el-popover placement="top" width="280" v-model="visible2">
                  <el-form :model="batchChild" :rules="rules" ref="batchChild" label-width="150px">

                    <el-form-item label="子机构" label-width="70px" prop="targetId">
                      <el-select v-if="!isSingle" no-data-text="无部门可选" class="wd150" v-model="batchChild.targetId" size="mini" placeholder="请选择子机构">
                        <el-option v-for="item in organization" :label="item.organizationName" :key="item.organizationId" :value="item.organizationId"></el-option>
                      </el-select>
                      <el-select v-if="isSingle" no-data-text="无部门可选" class="wd150" v-model="batchChild.targetId" size="mini" placeholder="请选择子机构">
                        <el-option v-for="item in childorganization" :label="item.organizationName" :key="item.organizationId" :value="item.organizationId"></el-option>
                      </el-select>
                    </el-form-item>

                  </el-form>
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="visible2 = false">取消</el-button>
                    <el-button type="primary" size="mini" @click.stop="saveBatchchild('batchChild')" :loading="childloding">确定</el-button>
                  </div>
                  <span slot="reference" v-if='!this.isNull' @click="batchNew">批量添加子机构</span>
                  <span slot="reference" v-else class="isNull">批量添加子机构</span>
                </el-popover>
              </div>
              <div class="tables_bom_cen">
                <span :class="this.moresave?'':'havemaoe'" @click="moresaves">批量保存</span>
              </div>
              <div class="tables_bom_right">
              </div>
              <div style="clear:both"></div>
            </div>
          </td>
        </tr>
      </table>
      <el-dialog :title="dialogTitle" :visible.sync="batchDialog" width="550px" :close-on-click-modal='false'>
        <div class="content">
          <el-form :model="batchChild" :rules="rules" ref="batchChild" label-width="150px">

            <el-form-item label="子机构" label-width="150px" prop="targetId">
              <el-select v-if="!isSingle" no-data-text="无部门可选" class="inputs" v-model="batchChild.targetId" size="mini" placeholder="请选择子机构">
                <el-option v-for="item in organization" :label="item.organizationName" :key="item.organizationId" :value="item.organizationId"></el-option>
              </el-select>
              <el-select v-if="isSingle" no-data-text="无部门可选" class="inputs" v-model="batchChild.targetId" size="mini" placeholder="请选择子机构">
                <el-option v-for="item in childorganization" :label="item.organizationName" :key="item.organizationId" :value="item.organizationId"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item class="btns">
              <el-button type="primary" size="small" @click.stop="saveBatchchild('batchChild')" :loading="childloding">确 定</el-button>
            </el-form-item>

          </el-form>
        </div>
      </el-dialog>
    </div>

    <div class="app-container" id="appss">
      <table width="100%" class="table-top" border="0">
        <tr>
          <th width="41%" colspan="4">政策备注信息</th>
          <th colspan="6" width="59%">
            <table width="100%" border="0" class="table-two">
              <tr>
                <th rowspan="2" width="16%">上/下游</th>
                <th colspan="2" width="34%" style="border-width: 0px 1px 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: white; border-bottom-color: white; border-left-color: white; border-image: initial;">交强险</th>
                <th colspan="2" width="34%" style="border-width: 0px 1px 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: white; border-bottom-color: white; border-left-color: white; border-image: initial;">商业险</th>
                <th rowspan="2" width="16%">操作</th>
              </tr>
              <tr>
                <th width="17%">佣金</th>
                <th width="17%" style="border-right: 1px solid white;">奖励</th>
                <th width="17%">佣金</th>
                <th width="17%">奖励</th>
              </tr>
            </table>
          </th>
        </tr>
      </table>
      <table width="100%" class="table-one" border="0">
        <tr>
          <td rowspan="5" width="10%">出险2次及以内（10座以下、5吨以下）</td>
          <td width="10%">
            交强
          </td>
          <td width="11%">
          </td>
          <td width="10%">
          </td>
          <td colspan="6">
            <div>####row1####</div>
          </td>
        </tr>
        <tr>
          <td>
            商三
          </td>
          <td>
          </td>
          <td>
          </td>
          <td colspan="6">
            <div>####row2####</div>
          </td>
        </tr>
        <tr>
          <td rowspan="3">
            交商同保、单商业（含车损）
          </td>
          <td rowspan="3">
            10座以下、5吨以下
          </td>
          <td>
            30万以下（含30万）
          </td>
          <td colspan="6">
            <div>####row3####</div>
          </td>
        </tr>
        <tr>
          <td>
            30-50（含50）
          </td>
          <td colspan="6">
            <div>####row4####</div>
          </td>
        </tr>
        <tr>
          <td>
            50万以上
          </td>
          <td colspan="6">
            <div>####row5####</div>
          </td>
        </tr>
        <tr>
          <td colspan="4" width="41%">
            出险2次及以上（交强、商业）
          </td>
          <td colspan="6">
            <div>####row6####</div>
          </td>
        </tr>
        <tr>
          <td width="41%" colspan="4"></td>
          <td width="59%" colspan="6">
            <div style="width:100%;min-height:45px;line-height:45px;">
              <div class="tables_bom_son">
                <el-popover placement="top" width="280" v-model="visible2">
                  <el-form :model="batchChild" :rules="rules" ref="batchChild" label-width="150px">

                    <el-form-item label="子机构" label-width="70px" prop="targetId">
                      <el-select v-if="!isSingle" no-data-text="无部门可选" class="wd150" v-model="batchChild.targetId" size="mini" placeholder="请选择子机构">
                        <el-option v-for="item in organization" :label="item.organizationName" :key="item.organizationId" :value="item.organizationId"></el-option>
                      </el-select>
                      <el-select v-if="isSingle" no-data-text="无部门可选" class="wd150" v-model="batchChild.targetId" size="mini" placeholder="请选择子机构">
                        <el-option v-for="item in childorganization" :label="item.organizationName" :key="item.organizationId" :value="item.organizationId"></el-option>
                      </el-select>
                    </el-form-item>

                  </el-form>
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="visible2 = false">取消</el-button>
                    <el-button type="primary" size="mini" @click.stop="saveBatchchild('batchChild')" :loading="childloding">确定</el-button>
                  </div>
                  <span slot="reference" v-if='!this.isNull' @click="batchNew">批量添加子机构</span>
                  <span slot="reference" v-else class="isNull">批量添加子机构</span>
                </el-popover>

              </div>
              <div class="tables_bom_cen">
                <span :class="this.moresave?'':'havemaoe'" @click="moresaves">批量保存</span>
              </div>
              <div class="tables_bom_right">
              </div>
              <div style="clear:both"></div>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import system from "@/components/system";
import "./../../styles/tables.scss";
export default {
  components: {},
  data() {
    return {
      visible2: false,
      policylist: [],
      iscanedit: false,
      moresave: false,
      isNull: false,
      batchDialog: false,
      dialogTitle: "",
      organization: [],
      isSingle: false,
      childloding: false,
      batchChild: {},
      id: "7ac8a357-a759-491b-a2f0-897e455269d7",
      rules: {
        targetId: [
          {
            required: true,
            message: "请选择对象",
            trigger: "change"
          }
        ]
      },
      datas: []
    };
  },
  filters: {
    isPercentage(val) {
      if (val == 0) {
        return "%";
      } else {
        return "元";
      }
    }
  },
  created() {
    const me = this;
    // this.getPolicyList();
    new system({
      batchid: "bde10256-bdcb-44ba-82f8-046bb58de6e3",
      created: function() {},
      success: function(vm) {
        console.log(vm);
        console.log(
          "its in you dream or in your life , if you can do it you maybe to a hero!"
        );

        vm.map(function(item, index) {
          // item = Object.assign({},item,{
          //    isbackshow:false,
          //    change1:false,
          //    change2:false,
          //    change3:false,
          //    change4:false,
          //  })
          item.isbackshow = false;
          item.change1 = false;
          item.change2 = false;
          item.change3 = false;
          item.change4 = false;
          // me.$set(item,)
        });
        //   let str = JSON.stringify(vm);
        //   me.datas = JSON.parse(str);
        me.policylist = vm;
        let str = JSON.stringify(vm);
        me.copypolicylist = JSON.parse(str);
        // console.log(me.datas)
      }
    });
  },
  mounted() {
    // const me = this;
    // this.getPolicyList();
    // new system({
    //   batchid:'bde10256-bdcb-44ba-82f8-046bb58de6e3',
    //    created:function(){
    //     },
    //     success: function(vm) {
    //       console.log(vm)
    //       console.log("its in you dream or in your life , if you can do it you maybe to a hero!")
    //      vm.map(function(item,index){
    //         // item = Object.assign({},item,{
    //         //    isbackshow:false,
    //         //    change1:false,
    //         //    change2:false,
    //         //    change3:false,
    //         //    change4:false,
    //         //  })
    //         item.isbackshow = false
    //         // me.$set(item,)
    //       })
    //       // me.datas = vm;
    //      // console.log(me.datas)
    //     }
    // })
  },
  methods: {
    focusselect(val) {
      val.currentTarget.select();
    },
    subfalse(index) {
      let str = JSON.stringify(this.copypolicylist[index]);
      Vue.set(this.policylist, index, JSON.parse(str));
      this.nowmoresave();
    },
    //判断moresave
    nowmoresave() {
      let aa = false;
      this.policylist.map(item => {
        if (item.isbackshow) {
          aa = true;
        }
        if (item.childOrgs !== null && item.childOrgs.length != 0) {
          item.childOrgs.map(val => {
            if (val.isbackshow) {
              aa = true;
            }
          });
        }
      });
      this.moresave = aa;
    },
    moresaves() {
      if (this.moresave) {
        console.log(this.policylist);
        let arr = [];
        let aa = false;
        this.policylist.map(item => {
          if (item.isbackshow) {
            item.extendID = item.policyItemRateId;
            arr.push(item);
          }
          if (item.isfront || item.issecon) {
            aa = true;
          }
          item.childOrgs.map(val => {
            if (val.isbackshow) {
              val.extendID = val.policyItemRateId;
              arr.push(val);
            }
            if (val.isfront || val.issecon) {
              aa = true;
            }
          });
        });
        if (aa == true) {
          this.$message({
            message: "数据不对",
            type: "warning"
          });
        } else {
          var txt = "确定批量保存吗？";
          this.$confirm(txt, "保存提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnClickModal: false
            // type: 'warning'
          }).then(() => {
            let params = {
              batchID: this.id,
              items: arr
            };
            this.post(params, "services/app/policy/LowerUpdate").then(rs => {
              if (rs.success) {
                console.log("success");
                console.log(rs);
                this.getPolicyList();
                this.$notify({
                  title: "修改成功",
                  message: "您已修改成功",
                  type: "success",
                  customClass: "el-notification-success"
                });
                this.moresave = false;
              } else {
                this.$notify.error({
                  title: "错误",
                  message: rs.error.message
                });
              }
            });
          });
        }
      }
    },
    //修改单挑政策数据
    subpolicy(item, index) {
      let obj = {
        policyItemRateId: item.id,
        lowerBrokerageBusiness: item.brokerageBusiness,
        lowerRewardBusiness: item.rewardBusiness,
        lowerBrokerageTraffic: item.brokerageTraffic,
        lowerRewardTraffic: item.rewardTraffic,
      };
      let upobj={
        policyId: item.id,
                upperBrokerageBusiness: item.brokerageBusiness,
                upperRewardBusiness: item.rewardBusiness,
                upperBrokerageTraffic: item.brokerageTraffic,
                upperRewardTraffic: item.rewardTraffic
      }
      if (item.isfront || item.issecon) {
        this.$message({
          message: "数据不对",
          type: "warning"
        });
      } else {
        this.loading2 = true;
        let arr = [];
        let url =''
        if(item.stream == 1){
          arr.push(upobj);
          url = "services/app/policy/UpdateUpperPolicyCustom"
        }else{
          arr.push(obj);
          url ="services/app/policy/LowerUpdate"
        }
        
        let params = {
          batchID:item.policyId,
          items: arr
        };
        this.post(params, url).then(rs => {
          if (rs.success) {
            console.log("success");
            console.log(rs);
            //this.getPolicyList()
            this.$notify({
              title: "修改成功",
              message: "您已修改成功",
              type: "success",
              customClass: "el-notification-success"
            });
            Vue.set(this.policylist[index], "isbackshow", false);
            Vue.set(this.policylist[index], "change1", false);
            Vue.set(this.policylist[index], "change2", false);
            Vue.set(this.policylist[index], "change3", false);
            Vue.set(this.policylist[index], "change4", false);
            let str = JSON.stringify(this.policylist[index]);
            Vue.set(this.copypolicylist, index, JSON.parse(str));
            this.nowmoresave();

            this.loading2 = false;
          } else {
            this.loading2 = false;
            this.$notify.error({
              title: "错误",
              message: rs.error.message
            });
          }
        });
      }
    },
    //信息表
    getPolicyList() {
      let params = {
        // 'id':'fdafdafd-e6eb-4068-ac7e-c09853094735'
        id: this.id
      };
      this.post(params, "services/app/policy/GetAllPolicyList").then(rs => {
        if (rs.success) {
          console.log("biaoshuju");
          console.log(rs.result.items);
          if (rs.result.items.length == 0) {
            this.isNull = true;
          }
          this.policylist = rs.result.items;
          let re = /^[0-9]+.?[0-9]*/;
          this.policylist.forEach(item => {
            if (item) {
              item.hovershow = false;
              item.Lowerpassiseditshow = false;
              item.isbackshow = false;
              item.isfront = false;
              item.issecon = false;
              item.change1 = false;
              item.change2 = false;
              item.change3 = false;
              item.change4 = false;
              item.detailshow = false;
              item.delete_show = false;
              if (item.childOrgs.length != 0) {
                item.childOrgs.map(val => {
                  val.hovershow = false;
                  item.isbackshow = false;
                  item.isfront = false;
                  item.issecon = false;
                  item.change1 = false;
                  item.change2 = false;
                  item.change3 = false;
                  item.change4 = false;
                });
              }
            }
          });
          let str = JSON.stringify(this.policylist);
          this.copypolicylist = JSON.parse(str);
        }
      });
    },
    //扩展input
    getchange_extendnum(val, indexout, index, name, types) {
      let aa = this.api.clearNoNum_target(val, 100, types);
      console.log(aa);
      Vue.set(this.policylist[indexout].childOrgs[index], name, aa);
      Vue.set(this.policylist[indexout].childOrgs[index], "isbackshow", true);
      this.moresave = true;
      //lowerRewardTraffic
      let a1 = parseFloat(
        this.policylist[indexout].childOrgs[index].lowerBrokerageTraffic
      );
      let a2 = parseFloat(
        this.policylist[indexout].childOrgs[index].lowerRewardTraffic
      );
      let a3 = parseFloat(
        this.policylist[indexout].childOrgs[index].lowerBrokerageBusiness
      );
      let a4 = parseFloat(
        this.policylist[indexout].childOrgs[index].lowerRewardBusiness
      );
      if (name == "lowerBrokerageTraffic") {
        Vue.set(this.policylist[indexout].childOrgs[index], "change1", true);
      }
      if (name == "lowerRewardTraffic") {
        Vue.set(this.policylist[indexout].childOrgs[index], "change2", true);
      }
      if (name == "lowerBrokerageBusiness") {
        Vue.set(this.policylist[indexout].childOrgs[index], "change3", true);
      }
      if (name == "lowerRewardBusiness") {
        Vue.set(this.policylist[indexout].childOrgs[index], "change4", true);
      }
      if (types == 0) {
        if (a1 + a2 > 100) {
          Vue.set(this.policylist[indexout].childOrgs[index], "isfront", true);
        } else {
          Vue.set(this.policylist[indexout].childOrgs[index], "isfront", false);
        }
        if (a3 + a4 > 100) {
          Vue.set(this.policylist[indexout].childOrgs[index], "issecon", true);
        } else {
          Vue.set(this.policylist[indexout].childOrgs[index], "issecon", false);
        }
      }
    },
    //下通input
    getchange_num(val, index, name, types) {
      let aa = this.api.clearNoNum_target(val, 100, types);
      Vue.set(this.policylist[index], name, aa);
      Vue.set(this.policylist[index], "isbackshow", true);
      this.moresave = true;
      let a1 = parseFloat(this.policylist[index].lowerBrokerageTraffic);
      let a2 = parseFloat(this.policylist[index].lowerRewardTraffic);
      let a3 = parseFloat(this.policylist[index].lowerBrokerageBusiness);
      let a4 = parseFloat(this.policylist[index].lowerRewardBusiness);
      if (name == "lowerBrokerageTraffic") {
        Vue.set(this.policylist[index], "change1", true);
      }
      if (name == "lowerRewardTraffic") {
        Vue.set(this.policylist[index], "change2", true);
      }
      if (name == "lowerBrokerageBusiness") {
        Vue.set(this.policylist[index], "change3", true);
      }
      if (name == "lowerRewardBusiness") {
        Vue.set(this.policylist[index], "change4", true);
      }
      if (types == 0) {
        if (a1 + a2 > 100) {
          Vue.set(this.policylist[index], "isfront", true);
        } else {
          Vue.set(this.policylist[index], "isfront", false);
        }
        if (a3 + a4 > 100) {
          Vue.set(this.policylist[index], "issecon", true);
        } else {
          Vue.set(this.policylist[index], "issecon", false);
        }
      }
    },
    //扩展取消
    subfalseextend(indexout, index) {
      let str = JSON.stringify(this.copypolicylist[indexout].childOrgs[index]);
      Vue.set(this.policylist[indexout].childOrgs, index, JSON.parse(str));
      this.nowmoresave();
    },
    //修改扩展信息
    subpolicychildOrgs(item, indexout, index) {
      let obj = {
        policyItemRateId: item.policyItemRateId,
        lowerBrokerageBusiness: item.lowerBrokerageBusiness,
        lowerRewardBusiness: item.lowerRewardBusiness,
        lowerBrokerageTraffic: item.lowerBrokerageTraffic,
        lowerRewardTraffic: item.lowerRewardTraffic,
        lowerBrokerageVehicleTax: item.lowerBrokerageVehicleTax,
        lowerRewardVehicleTax: item.lowerRewardVehicleTax
      };

      if (item.isfront || item.issecon) {
        this.$message({
          message: "数据不对",
          type: "warning"
        });
      } else {
        this.loading2 = true;
        let arr = [];
        arr.push(obj);
        let params = {
          batchID: this.id,
          items: arr
        };
        this.post(params, "services/app/policy/LowerUpdate").then(rs => {
          if (rs.success) {
            console.log("success");
            console.log(rs);
            //this.getPolicyList()
            this.$notify({
              title: "修改成功",
              message: "您已修改成功",
              type: "success",
              customClass: "el-notification-success"
            });
            Vue.set(
              this.policylist[indexout].childOrgs[index],
              "isbackshow",
              false
            );
            Vue.set(
              this.policylist[indexout].childOrgs[index],
              "change1",
              false
            );
            Vue.set(
              this.policylist[indexout].childOrgs[index],
              "change2",
              false
            );
            Vue.set(
              this.policylist[indexout].childOrgs[index],
              "change3",
              false
            );
            Vue.set(
              this.policylist[indexout].childOrgs[index],
              "change4",
              false
            );
            let str = JSON.stringify(
              this.policylist[indexout].childOrgs[index]
            );
            Vue.set(
              this.copypolicylist[indexout].childOrgs,
              index,
              JSON.parse(str)
            );
            this.nowmoresave();

            this.loading2 = false;
          } else {
            this.loading2 = false;
            this.$notify.error({
              title: "错误",
              message: res.error.message
            });
          }
        });
      }
    },
    //详情
    toDetail(val, see) {
      console.log(this.$route);
      //dawn_policydowninfo
      let filterType;
      if (see == "02") {
        filterType = 1;
      } else {
        filterType = 0;
      }
      if (this.$route.name == "policylower3_list") {
        this.$router.push({
          name: "down_policydowninfo",
          query: {
            batchId: this.id,
            policyId: val,
            status: this.info.state,
            stream: 2,
            Jurisdiction: this.Jurisdiction,
            filterType: filterType
          }
        });
      } else {
        this.$router.push({
          name: "adddown_policydowninfo",
          query: {
            batchId: this.id,
            policyId: val,
            status: this.info.state,
            stream: 2,
            Jurisdiction: this.Jurisdiction,
            filterType: filterType
          }
        });
      }
    },
    tocopy(ids) {
      if (this.$route.name == "policylower3_list") {
        this.$router.push({
          name: "down_policydowninfo",
          query: {
            batchId: this.id,
            policyId: ids,
            status: this.info.state,
            stream: 2,
            Jurisdiction: this.Jurisdiction,
            iscopy: true
          }
        });
      } else {
        this.$router.push({
          name: "adddown_policydowninfo",
          query: {
            batchId: this.id,
            policyId: ids,
            status: this.info.state,
            stream: 2,
            Jurisdiction: this.Jurisdiction,
            iscopy: true
          }
        });
      }
    },
    deletefalse(val) {
      this.$refs[val][0].doClose();
    },
    cancelpop(val){
       this.$refs[val][0].doClose();
    },
    //删除政策
    deletepolicy(val, e, refss) {
      console.log(val);
      let params = {
        //policyBatchType: 1,
        policyId: val
        //policyItemRatesID: val.policyItemRateId,
      };
      this.post(params, "services/app/policy/DeletePolicy").then(res => {
        console.log(res);
        if (res.success) {
          this.$notify({
            title: "删除成功",
            message: "您已成功删除一条政策",
            type: "success",
            customClass: "el-notification-success"
          });
          this.$refs[refss][0].doClose();
          this.policylist.splice(e, 1);
          if (this.policylist.length == 0) {
            this.isNull = true;
          }
        } else {
          this.$notify.error({
            title: "错误",
            message: res.error.message
          });
        }
      });
    },
    //批量添加子机构
    batchNew() {
      // this.dialogTitle = "批量添加子机构政策"
      this.isSingle = false;
      //this.batchDialog = true;
      this.batchChild = {};
      this.gethomes(this.id);
    },
    //获取组织
    gethomes(val) {
      //organization
      let params = {
        id: val
      };
      this.post(params, "services/app/policy/ChildOrganizations").then(res => {
        console.log(res);
        if (res.success) {
          console.log("zuzhi");
          console.log(res);
          this.organization = res.result.all;
        } else {
          this.$notify.error({
            title: "错误",
            message: res.error.message
          });
        }
      });
    },
    //单个增加子机构
    singleAdd(policyId) {
      this.childpolicyId = policyId;
   //  this.dialogTitle = "添加子机构政策";
      this.isSingle = true;
      //this.batchDialog = true;
      this.getChildhomes(policyId);
    },
    //批量or单个新增子机构保存
    saveBatchchild(formName) {
      const me = this;
      this.$refs[formName].validate(valid => {
        if (valid) {
          me.childloding = true;
          let params = {
            policyBatchId: this.id,
            extendType: 1,
            targetId: this.batchChild.targetId
          };
          if (me.isSingle) {
            params.policyId = this.childpolicyId;
          }
          this.post(params, "services/app/policy/CreateLowerPolicyExtend").then(
            rs => {
              console.log(rs);
              if (rs.success) {
                this.$notify({
                  title: "添加成功",
                  message: "批量添加子机构政策成功",
                  type: "success",
                  customClass: "el-notification-success"
                });
                me.batchDialog = false;
                me.batchChild.targetId = "";
                me.getPolicyList();
                me.childloding = false;
              } else {
                this.$notify.error({
                  title: "错误",
                  message: res.error.message
                });
                me.childloding = false;
              }
            }
          );
        } else {
          console.log("验证不通过");
        }
      });
    },
    //删除子机构
    deletChild(policyid, ratesid) {
      const me = this;
      let params = {
        policyId: policyid,
        policyItemRatesID: ratesid
      };
      this.$confirm("您确定要删除子机构政策吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.post(params, "services/app/policy/DeleteExtendPolicy").then(
          res => {
            if (res.success) {
              this.$notify({
                title: "删除成功",
                message: "删除子机构政策成功",
                type: "success",
                customClass: "el-notification-success"
              });
              me.getPolicyList();
            } else {
              this.$notify.error({
                title: "错误",
                message: res.error.message
              });
            }
          }
        );
      });
    },
    //获取组织
    getChildhomes(val) {
      //organization
      let params = {
        id: val
      };
      this.post(params, "services/app/policy/ChildOrganizations").then(res => {
        if (res.success) {
          this.childorganization = res.result.child;
        } else {
          this.$notify.error({
            title: "错误",
            message: res.error.message
          });
        }
      });
    },

    //数字小数点
    clearNoNum(obj, max) {
      obj = obj.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
      obj = obj.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
      obj = obj
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".");
      obj = obj.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
      if (obj.indexOf(".") < 0 && obj != "") {
        //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        obj = parseFloat(obj);
      }
      if (max && obj > max) {
        obj = max;
      }
      if (obj == "") {
        obj = 0;
      }
      console.log(obj);
      return obj;
    }
  }
};
</script>

<style lang='scss' scoped>
.wd150 {
  width: 150px;
}
.tables_contentall_in:last-child {
  border-bottom: 0;
}
.tables_contentall_in {
 // border-bottom: 1px solid #e8e8e8;
  width: 84%;
  float: left;
  .tables_content2 {
    position: relative;
    i {
      display: none;
      position: absolute;
      right: 6px;
      top: 0px;
      cursor: pointer;
      font-size: 13px;
    }
    .icon-plus {
      color: #019f6c;
    }
    .icon-shanchu {
      color: #cf1322;
      font-size: 15px;
    }
    &:hover {
      i {
        display: block;
      }
    }
    width: 19.5%;
    float: left;
    height: 45px;
  //  border-left: 1px solid #e8e8e8;
    line-height: 45px;
    text-align: center;
    padding: 0 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tables_content3 {
    width: 80.5%;
    float: left;
    height: 45px;
    border-left: 1px solid #e8e8e8;
    border-right: 1px solid #e8e8e8;
    position: relative;
    .tables_content3_inp {
      width: 50%;
      height: 100%;
      line-height: 45px;
      text-align: center;
      display: block;
      float: left;
      .tables_content3_inpin {
        display: block;
        float: left;
        width: 50%;
        height: 100%;
        line-height: 45px;
        text-align: center;
        .inputset {
          width: 50px;
          height: 22px;
          outline: none;
          background: #ffffff;
          border: 1px solid #cbcbcb;
          border-radius: 4px;
          text-align: right;
          padding-right: 5px;
        }
        .isfrontshow,
        .isseconshow {
          border: 1px solid red !important;
        }
        .isdis {
          background-color: #f5f7fa;
          border-color: #e4e7ed;
          color: #c0c4cc;
          cursor: not-allowed;
          color: #333;
        }
      }
    }
    .ischange1 input {
      border: 1px solid #ff9430 !important;
    }
    .ischange2 .inputset {
      border: 1px solid #ff9430 !important;
    }
    .ischange3 .inputset {
      border: 1px solid #ff9430 !important;
    }
    .ischange4 .inputset {
      border: 1px solid #ff9430 !important;
    }

    .tables_top3_frame {
      border-right: 1px solid #e8e8e8;
    }
  }
  .backshows {
    background: rgba(249, 225, 202, 0.5);
  }
}
.backshows:hover .poper_operation {
  display: block;
}
.poper_operation {
  position: absolute;
  top: 0;
  right: -106px;
  width: 100px;
  height: 40px;
  margin-top: 2.5px;
  background: #fff;
  border: 1px solid #ebeef5;
  color: #027dca;
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  display: none;
  line-height: 40px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);

  span:first-child {
    margin-right: 15px;
  }
}
.poper_operation::after {
  width: 6px;
  height: 6px;
  position: absolute;
  top: 50%;
  margin-top: -6px;
  display: block;
  content: "";
  left: -6px;
  width: 0;
  height: 0;
  border-width: 6px 6px 6px 0;
  border-style: solid;
  border-color: transparent #fff transparent transparent; /*透明 灰 透明 透明 */
}
.tables_line {
  width: 100%;
}
.tables_content4 {
  width: 16%;
  float: left;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #027dca;
  border-bottom: 1px solid #e8e8e8;
  .tablescont_right_edit {
    margin: 0 10px;
  }
  .tablescont_right_delete {
    color: red;
    margin-left: 10px;
  }
}

.tables_bom_son {
  color: #027dca;
  width: 16.3%;
  float: left;
  // border-left: 1px solid #e8e8e8;
  text-align: center;
  span {
    cursor: pointer;
  }
}
.tables_bom_cen {
  color: #027dca;
  width: 67.7%;
  height: 100%;
  float: left;
  border-right: 1px solid #e8e8e8;
  border-left: 1px solid #e8e8e8;
  box-sizing: border-box;
  text-align: center;
  span {
    cursor: pointer;
  }
  .havemaoe {
    color: #999;
  }
}
.tables_bom_right {
  width: 16%;
  height: 100%;
  float: left;
}
.isNull {
  color: #999 !important;
}
.content {
  width: 100%;

  overflow: auto;
  font-size: 12px;
}
.icon-lingxing {
  font-size: 8px;
  margin-right: 5px;
  color: #ff7819;
}
.inputs {
  width: 250px;
  font-size: 12px;
}
.btns {
  display: flex;
  justify-content: center;
  margin-left: -150px;
  margin-top: 30px;
}
</style>
